package com.qhy.springcloud.controller;

import com.qhy.springcloud.api.Dept;
import com.qhy.springcloud.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author qiuhongyu
 * @date 2020/11/13 11:08
 */
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 获取服务端口
     *
     * @return
     */
    @GetMapping("/getServerPort")
    public String getServerPort() {
        return deptService.getPort();

    }
    /**
     * 新增部门信息
     *
     * @param dept
     * @return
     */
    @PostMapping("addDept")
    public boolean addDept(Dept dept) {
        boolean b = deptService.addDept(dept);
        return true;
    }

    /**
     * 根据部门id查询部门信息
     *
     * @param id
     * @return
     */
    @GetMapping("/queryDept/{id}")
    public Dept queryDept(@PathVariable("id") Long id) {
        Dept dept = deptService.queryDept(id);
        return dept;
    }

    @GetMapping("queryDepts")
    public List<Dept> queryDepts() {
        List<Dept> deptList = deptService.queryDepts();
        return deptList;
    }


}
